using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using Microsoft.Practices.RecipeFramework;
using VSSDKAssist.Assets.Helpers;
using VSSDKAssist.Assets.Actions.Base;
using System.Globalization;

namespace VSSDKAssist.Recipes.CreateToolOptionsPage
{
	/// <summary>
	/// Action that adds/update the AddProvideOptionPage attribute
	/// </summary>
	public class AddProvideOptionPageAttributeAction : ActionBase
	{
		#region Properties
		private CodeClass codeClass;

		/// <summary>
		/// Gets or sets the code class.
		/// </summary>
		/// <value>The code class.</value>
		[Input(Required = true)]
		public CodeClass CodeClass
		{
			get { return codeClass; }
			set { codeClass = value; }
		}

		private string optionPageName;

		/// <summary>
		/// Gets or sets the name of the option page.
		/// </summary>
		/// <value>The name of the option page.</value>
		[Input(Required = true)]
		public string OptionPageName
		{
			get { return optionPageName; }
			set { optionPageName = value; }
		}

		private string optionPageNamespace;

		/// <summary>
		/// Gets or sets the option page namespace.
		/// </summary>
		/// <value>The option page namespace.</value>
		[Input(Required = true)]
		public string OptionPageNamespace
		{
			get { return optionPageNamespace; }
			set { optionPageNamespace = value; }
		}

		private string categoryName;

		/// <summary>
		/// Gets or sets the name of the category.
		/// </summary>
		/// <value>The name of the category.</value>
		[Input(Required = true)]
		public string CategoryName
		{
			get { return categoryName; }
			set { categoryName = value; }
		}

		private string categoryCaptionResourceId;

		/// <summary>
		/// Gets or sets the category caption resource id.
		/// </summary>
		/// <value>The category caption resource id.</value>
		[Input(Required = true)]
		public string CategoryCaptionResourceId
		{
			get { return categoryCaptionResourceId; }
			set { categoryCaptionResourceId = value; }
		}

		private string pageName;

		/// <summary>
		/// Gets or sets the name of the page.
		/// </summary>
		/// <value>The name of the page.</value>
		[Input(Required = true)]
		public string PageName
		{
			get { return pageName; }
			set { pageName = value; }
		}

		private string pageCaptionResourceId;

		/// <summary>
		/// Gets or sets the page caption resource id.
		/// </summary>
		/// <value>The page caption resource id.</value>
		[Input(Required = true)]
		public string PageCaptionResourceId
		{
			get { return pageCaptionResourceId; }
			set { pageCaptionResourceId = value; }
		}

		private bool supportsAutomation;

		/// <summary>
		/// Gets or sets a value indicating whether [supports automation].
		/// </summary>
		/// <value><c>true</c> if [supports automation]; otherwise, <c>false</c>.</value>
		[Input(Required = true)]
		public bool SupportsAutomation
		{
			get { return supportsAutomation; }
			set { supportsAutomation = value; }
		}
		#endregion

		#region Protected Implementation
		/// <summary>
		/// Called when [execute].
		/// </summary>
		protected override void OnExecute()
		{
			string attName = "ProvideOptionPageAttribute";
			string attValue = string.Format(
				CultureInfo.CurrentCulture,
				"typeof({0}.{1}), \"{2}\", \"{3}\", {4}, {5}, {6}",
				this.OptionPageNamespace,
				this.OptionPageName,
				this.CategoryName,
				this.PageName,
				this.CategoryCaptionResourceId,
				this.PageCaptionResourceId,
				this.SupportsAutomation.ToString().ToLower(CultureInfo.CurrentCulture));

			FileCodeModelHelper.AddAttribute(codeClass, attName, attValue, false);
		}
		#endregion
	}
}